package com.xysq.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xysq.util.PropertiesUtil;
import com.rockcent.model.CouponBO;
import com.xysq.lemon.R;
import com.xysq.util.UseUtil;

import butterknife.InjectView;

/**
 * Created by huangdongkai on 2015/8/9.
 */
public class SearchListAdapter extends BaseDataAdapter<CouponBO> {
    private ViewHolder holder;

    public SearchListAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_search_list, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        CouponBO couponModel = itemList.get(position);
        holder.nameTxt.setText(couponModel.getName());
/*        if(couponModel.getModelType() == ModelType.CASH || couponModel.getModelType() == ModelType.ALL) {
            holder.priceTxt.setText(couponModel.getEstimateAmount() + "元");
        } else {
            holder.priceTxt.setText("0元");
        }*/
        if (couponModel.getCategory() != null) {
            if (couponModel.getCategory().equals("B")) {
                holder.priceTxt.setText("￥" + UseUtil.handlePrice(couponModel.getEstimateAmount()));
            } else {
                holder.priceTxt.setText("￥" + UseUtil.handlePrice(couponModel.getPrice()));
            }
        }
        holder.schoolTxt.setText(couponModel.getExtend1());
        if (!couponModel.getPicUrl().isEmpty()) {
            String picUrl;
            if (couponModel.getPicUrl().indexOf(";") != -1) {
                picUrl = couponModel.getPicUrl().split(";")[0];
            } else {
                picUrl = couponModel.getPicUrl();
            }
            picUrl = PropertiesUtil.getImageServer() + picUrl;
            imageLoader.displayImage(picUrl, holder.picImg);
        }
        return convertView;
    }

    static class ViewHolder extends BaseViewHolder {
        @InjectView(R.id.txt_customer_name)
        TextView nameTxt;
        @InjectView(R.id.img_pic)
        ImageView picImg;
        @InjectView(R.id.txt_price)
        TextView priceTxt;
        @InjectView(R.id.txt_school)
        TextView schoolTxt;

        public ViewHolder(View view) {
            super(view);
        }
    }
}
